using UnityEngine;
using System.Collections;

/// \class  gkDetachParticleSystemOnDestruction
/// \brief  Detach a particle system on destruction
[AddComponentMenu("GK/Engine/Core/Particle/gkDetachParticleSystemOnDestruction")]
public class gkDetachParticleSystemOnDestruction : MonoBehaviour 
{
	/// The particle system to detach
	public GameObject ParticleSystem;
	
	/// \brief  Called on the game object destruction
	void OnDestroy()
	{
		DetachParticleSystem();	
	}
	
	/// \brief  Setup the particle system
	void DetachParticleSystem()
	{
		// We detach the active particle system and set it to auto-destruction (destruction when all the particle have died)
		if(ParticleSystem != null)
		{
			ParticleSystem.transform.parent = null;
			ParticleSystem.GetComponent<ParticleAnimator>().autodestruct = true; 
			ParticleSystem.particleEmitter.emit = false;
		}
	}
}
